package com.tangchao.client.sdh.view
{
	import com.tangchao.client.sdh.sdhinterface.Test;
	import com.tangchao.client.sdh.vo.JieSuanVo;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	public class JieSuan extends MovieClip
	{
		private var _mcWinType:MovieClip;
		private var _btnOK:SimpleButton;
		private var _parentUI:SanDaHaPanel;
		
		private var _difen:TextField;
		private var _beishu:TextField;
		private var _defen:TextField;
		private var _type:TextField;
		
		private var _name1:TextField;
		private var _name1Dao:TextField;
		private var _name1Win:TextField;
		private var _name1Score:TextField;
		private var _name2:TextField;
		private var _name2Dao:TextField;
		private var _name2Win:TextField;
		private var _name2Score:TextField;
		private var _name3:TextField;
		private var _name3Dao:TextField;
		private var _name3Win:TextField;
		private var _name3Score:TextField;
		private var _name4:TextField;
		private var _name4Dao:TextField;
		private var _name4Win:TextField;
		private var _name4Score:TextField;
		
		private var _nextDiFen:int;
		
		public function JieSuan()
		{
			init();
		}
		
		private function init()
		{
			_mcWinType  =  getChildByName("dizhu_nongmin") as MovieClip;
			_mcWinType.stop();
			
			_difen=getChildByName("tfDiFen") as TextField;
			_beishu=getChildByName("tfBeiShu") as TextField;
			_defen = getChildByName("tfDefen") as TextField;
			_type  = getChildByName("tfType") as TextField;
			
			_name1=getChildByName("tfName1") as TextField;
			_name1Dao=getChildByName("tfName1Dao") as TextField;
			_name1Win=getChildByName("tfName1Win") as TextField;
			_name1Score=getChildByName("tfName1Score") as TextField;
			
			_name2=getChildByName("tfName2") as TextField;
			_name2Dao=getChildByName("tfName2Dao") as TextField;
			_name2Win=getChildByName("tfName2Win") as TextField;
			_name2Score=getChildByName("tfName2Score") as TextField;
			
			_name3=getChildByName("tfName3") as TextField;
			_name3Dao=getChildByName("tfName3Dao") as TextField;
			_name3Win=getChildByName("tfName3Win") as TextField;
			_name3Score=getChildByName("tfName3Score") as TextField;
			
			_name4=getChildByName("tfName4") as TextField;
			_name4Dao=getChildByName("tfName4Dao") as TextField;
			_name4Win=getChildByName("tfName4Win") as TextField;
			_name4Score=getChildByName("tfName4Score") as TextField;
			
			_btnOK = getChildByName("btnOK") as SimpleButton;
			_btnOK.addEventListener(MouseEvent.CLICK, onOK);
		}
		
		public function set parentUI(ui:SanDaHaPanel):void
		{
			_parentUI = ui;
		}
		
		private function onOK(e:MouseEvent):void
		{
			if(_parentUI)
			{
				_parentUI.onGameReset(_nextDiFen);
			}
		}
		
		/*
		*设置角色结算数据
		*/
		public function create(v:JieSuanVo)
		{
			_difen.text=v.difen;
			_beishu.text=v.beishu;
			if(v.role1)
			{
				_name1.text=v.role1.name;
				_name1Dao.text=v.role1.dao;
				_name1Win.text=v.role1.isWin;
				_name1Score.text=v.role1.score;
			}
			
			if(v.role2)
			{
				_name2.text=v.role2.name;
				_name2Dao.text=v.role2.dao;
				_name2Win.text=v.role2.isWin;
				_name2Score.text=v.role2.score;
			}
			
			if(v.role3)
			{
				_name3.text=v.role3.name;
				_name3Dao.text=v.role3.dao;
				_name3Win.text=v.role3.isWin;
				_name3Score.text=v.role3.score;
			}
			
			if(v.role4)
			{
				_name4.text=v.role4.name;
				_name4Dao.text=v.role4.dao;
				_name4Win.text=v.role4.isWin;
				_name4Score.text=v.role4.score;
			}
		}
		
		private function findSting(srcStr:String, dstArr:Array):Boolean
		{
			var i:int;
			var strTmp:String;
			
			for(i=0; i<dstArr.length; i++)
			{
				strTmp = dstArr[i] as String;
				if(strTmp == srcStr)
				{
					return true;
				}
			}
			return false;
		}
		
		public function update(ret:Array, isSurrend:Boolean = false):void
		{
			var winArr:Array;
			var itemArr:Array;
			var nameTmp:String;
			var winNameTmp:String;
			var isWin:Boolean = false;
			var stat:int;
			var i:int;
			var beiShu:int;
			var mode:int;
			var retType:int;
			var defen:int;
			var jiaofen:int;
			
			if(ret)
			{
				
				mode = ret[13] as int;
				_nextDiFen = ret[14] as int;
				retType = ret[15] as int;
				defen = ret[16] as int;
				jiaofen = ret[17] as int;
				switch(retType)
				{
					case 1:
						_type.text = "庄家跨庄";
						break;
					case 2:
						_type.text = "庄家小光";
						break;
					case 3:
						_type.text = "庄家大光";
						break;
					case -1:
						_type.text = "庄家过庄";
						break;
					case -2:
						_type.text = "闲家小光";
						break;
					case -3:
						_type.text = "闲家大光";
						break;
					default:
						_type.text = "";
						break;
				}
//				_beishu.text= int(ret[0]).toString();
				_defen.text = defen.toString();
				
				_difen.text= jiaofen.toString();
				
				winArr     = ret[0] as Array;
				
				if(winArr.length == 1)
				{
					_mcWinType.gotoAndStop(1);
				}
				else
				{
					_mcWinType.gotoAndStop(3);
				}
				
				nameTmp = ret[1] as String; 
				itemArr = ret[3] as Array;
				if(itemArr && nameTmp)
				{
					stat = itemArr[1] as int;
					switch(stat)
					{
						case 1:
							_name1Dao.text = "倒";
							break;
						case -1:
							_name1Dao.text = "跟";
							break;
						default:
							_name1Dao.text = "无";
							break;
						
					}
					_name1.text=nameTmp;
					if(findSting(nameTmp, winArr))
					{
						_name1Win.text= "胜";
					}
					else
					{
						_name1Win.text= "负";
					}
					beiShu = itemArr[2] as int;
					if(beiShu != 0)
					{
						_name1Dao.appendText("X"+beiShu.toString());
					}
					_name1Score.text=int(itemArr[0]).toString();
					
				}
				
				nameTmp = ret[4] as String; 
				itemArr = ret[6] as Array;
				if(itemArr && nameTmp)
				{
					stat = itemArr[1] as int;
					switch(stat)
					{
						case 1:
							_name2Dao.text = "倒";
							break;
						case -1:
							_name2Dao.text = "跟";
							break;
						default:
							_name2Dao.text = "无";
							break;
						
					}
					_name2.text=nameTmp;
					if(findSting(nameTmp, winArr))
					{
						_name2Win.text= "胜";
					}
					else
					{
						_name2Win.text= "负";
					}
					beiShu = itemArr[2] as int;
					if(beiShu != 0)
					{
						_name2Dao.appendText("X"+beiShu.toString());
					}
					_name2Score.text=int(itemArr[0]).toString();
				}
				
				nameTmp = ret[7] as String; 
				itemArr = ret[9] as Array;
				if(itemArr && nameTmp)
				{
					stat = itemArr[1] as int;
					switch(stat)
					{
						case 1:
							_name3Dao.text = "倒";
							break;
						case -1:
							_name3Dao.text = "跟";
							break;
						default:
							_name3Dao.text = "无";
							break;
						
					}
					_name3.text=nameTmp;
					if(findSting(nameTmp, winArr))
					{
						_name3Win.text= "胜";
					}
					else
					{
						_name3Win.text= "负";
					}
					beiShu = itemArr[2] as int;
					if(beiShu != 0)
					{
						_name3Dao.appendText("X"+beiShu.toString());
					}
					_name3Score.text=int(itemArr[0]).toString();
				}
				
				nameTmp = ret[10] as String; 
				itemArr = ret[12] as Array;
				if(itemArr && nameTmp)
				{
					stat = itemArr[1] as int;
					switch(stat)
					{
						case 1:
							_name4Dao.text = "倒";
							break;
						case -1:
							_name4Dao.text = "跟";
							break;
						default:
							_name4Dao.text = "无";
							break;
						
					}
					_name4.text=nameTmp;
					if(findSting(nameTmp, winArr))
					{
						_name4Win.text= "胜";
					}
					else
					{
						_name4Win.text= "负";
					}
					beiShu = itemArr[2] as int;
					if(beiShu != 0)
					{
						_name4Dao.appendText("X"+beiShu.toString());
					}
					_name4Score.text=int(itemArr[0]).toString();
				}
			}
		}
	}
}